package com.example.healthcondition.controller;

import com.example.healthcondition.entity.ExerciseRecords;
import com.example.healthcondition.services.ExerciseService;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/login/home/exercise")
public class ExerciseController {
    private final ExerciseService exerciseService;

    public ExerciseController(ExerciseService exerciseService) {
        this.exerciseService = exerciseService;
    }

    @PostMapping("/add")
    public Map<String, Object> addExercise(@RequestBody ExerciseRecords exerciseRecords) {
        return exerciseService.addExercise(exerciseRecords);
    }

    // 更新运动记录
    @PostMapping("/update")
    public Map<String, Object> updateExercise(@RequestBody ExerciseRecords exerciseRecord) {
        return exerciseService.updateExercise(exerciseRecord);
    }

    // 删除运动记录
    @PostMapping("/delete")
    public Map<String, Object> deleteExercise(@RequestBody Map<String, Integer> request) {
        Integer recordId = request.get("record_id");
        if (recordId == null) {
            Map<String, Object> result = new HashMap<>();
            result.put("message", "record_id 不能为空");
            result.put("flag", false);
            return result;
        }
        return exerciseService.deleteExercise(recordId);
    }
}
